<html xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui" >

    <ui:composition template="layout.xhtml">
        <ui:define name="corpo">
            <h:form acceptcharset="utf-8" id="verImovel" enctype="multipart/form-data"> 


                <div id="breadcrumb">
                    <p:commandLink  actionListener="#{managerIndex.redirect('index.xhtml')}" value="Inicio" update="@form" immediate="true"/> >
                    <p:commandLink  actionListener="#{managerIndex.redirect('indexImovel.xhtml')}" value="Imóvel" update="@form" immediate="true"/> >
                    <p:commandLink  value="Visualizar Imóvel" update="@form" immediate="true"/>
                </div>

                <p:panel header="Visualizando Imóvel - #{managerBuscarImovel.verImovel.registro}">                        
                    <p:messages showDetail="true" id="msg" />



                    <fieldset class="ui-fieldset">
                        <legend><h:outputLabel value="Cartório"/></legend>
                        <h:panelGrid style="float: right;" columns="1">
                            <h:commandButton action="#{managerBuscarImovel.escritura(managerBuscarImovel.verImovel)}" 
                                             value="Gerar Registro" 
                                             style="color:#ffffff;font-weight: bold;width: 150px;"  />

                            

                        </h:panelGrid>
                        <h:panelGrid  columns="4" border="0" style="width:40%; margin-left: 20px;" styleClass="textAlignRightBold">  
                            
                            <h:outputLabel value="Origem: " />
                            <h:outputText value="#{managerBuscarImovel.verImovel.operacao.tipo}" />

                            <h:outputLabel value="" />
                            <h:outputLabel value="" />
                            
                            <h:outputLabel value="Livro: " />
                            <h:outputText value="#{managerBuscarImovel.verImovel.livro.titulo}" />
                            
                            <h:outputLabel value="Folha(s): " />
                            <h:outputText value="#{managerBuscarImovel.verImovel.folhasString}" />

                            <h:outputLabel value="Registro: "/> 
                            <h:outputText value="#{managerBuscarImovel.verImovel.registro}" />

                            <h:outputLabel value="Data:"/>                       
                            <h:outputText value="#{managerBuscarImovel.verImovel.dataCadastro}">
                                <f:convertDateTime pattern="dd/MM/yyyy"/>
                            </h:outputText>
                            
                        </h:panelGrid>
                    </fieldset>
                    <br/>
                    <fieldset class="ui-fieldset">
                        <legend><h:outputLabel value="Titulo"/></legend>
                        <h:panelGrid columns="2" id="panelGridTitulo" styleClass="textAlignRightBold">
                            <h:outputLabel value="Titulo: "/> 
                            <h:outputText value="#{managerBuscarImovel.verTransferencia.titulo.nome}"/>

                            <h:outputLabel value="Forma titulo: " />
                            <h:outputText value="#{managerBuscarImovel.verTransferencia.formaTitulo}" />
                        </h:panelGrid>
                    </fieldset>
                    <br/>
                    
                    <p:tab id="tabRegistroAnterior"  >
                        <fieldset class="ui-fieldset" >
                            <legend><h:outputLabel value="Registro Anterior"/></legend>
                            <h:panelGrid columns="2" id="panelGridRegAnterior" styleClass="textAlignRightBold">
                                
                                <h:outputLabel value="* Imóvel não possui Registro Anterior " 
                                                   style="margin-left:20px;"
                                                   rendered="#{empty managerBuscarImovel.verImovel.imovelAnterior}" />
                                
                                <h:outputLabel value="Número do(s) Registro(s):"
                                               rendered="#{!empty managerBuscarImovel.verImovel.imovelAnterior}" />
                                
                                <p:row>
                                    
                                    <ui:repeat value="#{managerBuscarImovel.verImovel.imovelAnterior}" var="info">
                                        <p:commandLink value="#{info.registro}" 
                                                       actionListener="#{managerBuscarImovel.verAnterior(info)}"
                                                       onclick="dialogAnterior.show()" process="@this"
                                                       update=":verImovel:panelGridEndTipoada" />
                                        <h:outputText value=", "/>
                                    </ui:repeat>
                                    
                                    <h:outputLabel value="#{managerBuscarImovel.verImovel.imovelAnteriorSemCadastro}" />
                                </p:row>
                                
                            </h:panelGrid>
                        </fieldset>
                        <p:dialog id="verAnterior" header="Registro Anterior " 
                                  widgetVar="dialogAnterior" modal="true" resizable="false"
                                  showEffect="clip" hideEffect="fold" width="400" height="200">  
                            <p:ajax event="close" listener="#{managerBuscarImovel.ImovelAnteriorClear()}"/> 
                            <h:panelGrid columns="4" style="width: 100%" id="panelGridEndTipoada" styleClass="textAlignRightBold">
                                <h:outputLabel value="Registro: "/>
                                <h:outputText value="#{managerBuscarImovel.verImovelAnterior.registro}"/>

                                <h:outputLabel value="Data: "/>
                                <h:outputText value="#{managerBuscarImovel.verImovelAnterior.dataCadastro}">
                                    <f:convertDateTime pattern="dd/MM/yyyy"/>
                                </h:outputText>


                                <h:outputLabel value="Objeto: "/>
                                <h:outputText value="#{managerBuscarImovel.verImovelAnterior.objeto.tipo}"/>
                                <h:outputText value=""/>
                                <h:outputText value=""/>

                                <h:outputLabel value="Titulo: "/>
                                <h:outputText value="#{managerBuscarImovel.verTransImovelAnterior.titulo.nome}"/>

                                <h:outputText value=""/>
                                <h:outputText value=""/>

                                <h:outputLabel value="Forma Titulo: "/>
                                <h:outputText value="#{managerBuscarImovel.verTransImovelAnterior.formaTitulo}"/>

                            </h:panelGrid>
                        </p:dialog>
                    </p:tab>
                    
                    <br/>
                    <fieldset class="ui-fieldset">
                        <legend><h:outputLabel value="Objeto"/></legend>
                        <h:panelGrid columns="2" style="margin-left: 27px ;" id="panelGridEndTipo" styleClass="textAlignRightBold">
                            <h:outputLabel value="Objeto: "/> 
                            <h:outputText value="#{managerBuscarImovel.verObjeto.tipo}"/> 
                            <h:outputLabel value="Área Original: "/>
                            <h:outputText value="#{managerBuscarImovel.verObjeto.areaOriginal}"/>
                            
                            <h:outputLabel value="Área Atual: "/>
                            <h:outputText value="#{managerBuscarImovel.verObjeto.areaAtual}"/>
                            
                            <h:outputLabel value="Descrição: "/>
                            <h:outputText value="#{managerBuscarImovel.verObjeto.descricao eq null ? '-': managerBuscarImovel.verObjeto.descricao}"/>
                            
                        </h:panelGrid>

                        <br/>
                        <fieldset class="ui-fieldset">
                            <legend><h:outputLabel value="Endereço do Imóvel"/></legend>
                            <div style="float: right; position: relative;">
                                <p:commandButton icon="ui-icon-circle-close" value="Ver Mapa" 
                                                 onclick="verMap.show()" disabled="#{empty managerBuscarImovel.verObjeto.geoReferenciamento}"/>
                            </div>

                            <h:panelGrid columns="4" id="panelGridEnd" styleClass="textAlignRightBold">
                                <h:outputLabel value="Tipo: "/>                                                
                                <h:outputText value="#{managerBuscarImovel.verObjeto.tipo_logradouro}"/>                                                

                                <h:outputLabel value="Cep: "/>
                                <h:outputText value="#{managerBuscarImovel.verObjeto.cep}" id="enderecocep"/>

                                <h:outputLabel value="Logradouro: "/>   
                                <h:outputText value="#{managerBuscarImovel.verObjeto.logradouro}" id="enderecoRua" />

                                <h:outputLabel value="Nº: " />   
                                <h:outputText value="#{managerBuscarImovel.verObjeto.numero}" id="enderecoNumero" />

                                <h:outputLabel value="Bairro: " />
                                <h:outputText value="#{managerBuscarImovel.verObjeto.bairro}" id="enderecoBairro"  />

                                <h:outputLabel value=" " />
                                <h:outputLabel value=" " />

                                <h:outputLabel value="Cidade: "/>
                                <h:outputText value="#{managerBuscarImovel.verObjeto.cidade.nom_cidade}"/>

                                <h:outputLabel  value="Estado: " />
                                <h:outputText  value="#{managerBuscarImovel.verObjeto.estado.nom_estado} " />


                            </h:panelGrid>

                            <br/>
                        </fieldset>
                        <br/>
                        <fieldset class="ui-fieldset">
                            <legend><h:outputLabel value="Confrontações "/></legend>   
                            <!--                            <h:panelGrid columns="4"  styleClass="textAlignRightBold">  -->
                            <h:outputLabel value="* Não Informado "  
                                           rendered="#{managerBuscarImovel.verObjeto.frente eq null ? true : false
                                                       and managerBuscarImovel.verObjeto.ladoDireito eq null ? true : false
                                                       and managerBuscarImovel.verObjeto.ladoEsquerdo eq null ? true : false
                                                       and managerBuscarImovel.verObjeto.fundo eq null ? true : false}"/>
                            
                            
                            
                            <h:outputLabel value="Frente: "   rendered="#{managerBuscarImovel.verObjeto.frente eq null ? false : true}"/>
                            <h:outputText id="frente" value="#{managerBuscarImovel.verObjeto.frente}" />
                            <h:outputLabel value=", Lado Direito: "   rendered="#{managerBuscarImovel.verObjeto.ladoDireito eq null ? false : true}"/>
                            <h:outputText id="direito" value="#{managerBuscarImovel.verObjeto.ladoDireito}" />
                            <h:outputLabel value=", Lado Esquerdo: "  rendered="#{managerBuscarImovel.verObjeto.ladoEsquerdo eq null ? false : true}"/>
                            <h:outputText id="esquerdo" value="#{managerBuscarImovel.verObjeto.ladoEsquerdo}" />
                            <h:outputLabel value=", Fundo: "   rendered="#{managerBuscarImovel.verObjeto.fundo eq null ? false : true}"/>
                            <h:outputText id="fundo" value="#{managerBuscarImovel.verObjeto.fundo}" />
                            <!--                            </h:panelGrid>-->
                        </fieldset>
                        <br/>
                    </fieldset>
                    <br/>  
                    <fieldset class="ui-fieldset">
                        <legend><h:outputLabel value="Transferências"/></legend>

                        <p:dataTable id="imovelTable2" var="imovels" 
                                     value="#{managerBuscarImovel.lstVerTransf}" emptyMessage="Nenhum registro encontrado" 
                                     paginator="true" rows="5"
                                     paginatorPosition="bottom"
                                     paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"  
                                     rowsPerPageTemplate="5,10,15"
                                     draggableColumns="true"
                                     >  
                            <f:facet name="header">  
                                Transferências do Imóvel #{imovels.imovel.registro}
                            </f:facet>

                            <p:column style="width:16px">  
                                <p:rowToggler />  
                            </p:column>
                            <p:column style="width:90px;">  
                                <f:facet name="header" >   
                                    Registro   
                                </f:facet>  
                                <h:outputText value="#{imovels.imovel.registro}" />  
                            </p:column>
                            <p:column>  
                                <f:facet name="header" >   
                                    Titulo 
                                </f:facet>  
                                <h:outputText value="#{imovels.titulo.nome}" escape="false" />  
                            </p:column>
                            <p:column>  
                                <f:facet name="header" >   
                                    Adquirente
                                </f:facet>  
                                <ui:repeat value="#{imovels.adquirente}" var="ad" >
<!--                                    <h:outputText value="#{imovels.adquirente.isEmpty() ? '-' : imovels.adquirente.toString().replace('[', '').replace(']', '') }" escape="false" />  -->
                                    - <p:commandLink  actionListener="#{managerVisualizarPessoa.redirect('visualizarPessoa.xhtml',ad)}" value="#{ad.nome}" />
                                    <br/>
                                </ui:repeat>

                            </p:column>
                            <p:column>  
                                <f:facet name="header" >   
                                    Transmitente
                                </f:facet>  
                                <ui:repeat value="#{imovels.transmitente}" var="tra" >
                                    - <p:commandLink  actionListener="#{managerPessoa.visualizarPessoa(tra)}" value="#{tra.nome}" />
                                    <br/>
                                </ui:repeat>
<!--                                <h:outputText value="#{imovels.transmitente.isEmpty() ? '-' : imovels.transmitente.toString().replace('[', '').replace(']', '')}" escape="false" />  -->
                            </p:column>
                            <p:rowExpansion >  
                                
                                <h:outputText value="Forma Titulo: #{imovels.formaTitulo}" />  
                                <br />
                                <h:outputText value="Valor: #{imovels.valor}" 
                                              rendered="#{imovels.valor eq null ? false : imovels.valor eq 0 ? false : true}" />   
                                
                                <p:commandLink value="Anexos" style="float:right;" />
                                <br/>
                                <br/>
                                <div style="float:right;">
                                    <h:outputText value="Transferência realizada em: "/>
                                    <h:outputText value="#{imovels.dataCadastro}">
                                        <f:convertDateTime pattern="dd/MM/yyyy HH:mm:ss"/>
                                    </h:outputText>
                                    <h:outputLabel value=" por  "  />  
                                    <h:outputText value=" #{imovels.usuario.login}" style="font-weight:bold;" />   
                                </div>

                            </p:rowExpansion> 
                            <p:column style="width:90px;" headerText="Data" sortBy="#{imovels.dataCadastro}">  
                                <h:outputText value="#{imovels.dataCadastro}">
                                    <f:convertDateTime pattern="dd/MM/yyyy"/>
                                </h:outputText>
                            </p:column>    
                        </p:dataTable>
                        <p:blockUI block="imovelTable2" trigger="imovelTable2">  
                            CARREGANDO...<br />  
                            <p:graphicImage value="/media/img/ajax-loader.gif"/>  
                        </p:blockUI>
                    </fieldset>
                    <br/>
                    <fieldset class="ui-fieldset">
                        <legend><h:outputLabel value="Averbações"/></legend>

                        <p:dataTable id="averbacaoDataTable" var="aver" 
                                     value="#{managerBuscarImovel.verImovel.averbacao}" 
                                     emptyMessage="Nenhuma Averbação encontrada" 
                                     paginator="true" rows="5"
                                     widgetVar="averbacaoDataTable2"
                                     paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"  
                                     paginatorPosition="bottom"
                                     rowsPerPageTemplate="5,10,15"
                                     draggableColumns="true"
                                     >  
                            <f:facet name="header">  
                                Averbações do Imóvel
                            </f:facet>

                            <p:column style="width:16px">  
                                <p:rowToggler />  
                            </p:column>
                            <p:column style="width:90px;">  
                                <f:facet name="header" >   
                                    Número   
                                </f:facet>  
                                <h:outputText value="#{aver.numero}" />  
                            </p:column>
                            <p:column>  
                                <f:facet name="header" >   
                                    Descricao 
                                </f:facet>  
                                <h:outputLabel value="#{aver.descricao.length() > 200 ? aver.descricao.substring(1, 200) : aver.descricao}" escape="false"/>  
                            </p:column>
                            <p:rowExpansion >  

                                <h:outputLabel value="#{aver.descricao}" escape="false" style="text-align: justify; text-justify: auto"/> 

                            </p:rowExpansion> 
                            <p:column style="width:90px;" headerText="Data" sortBy="#{aver.dataAverbacao}">  
                                <h:outputText value="#{aver.dataAverbacao}">
                                    <f:convertDateTime pattern="dd/MM/yyyy"/>
                                </h:outputText>
                            </p:column>    
                        </p:dataTable>
                        <p:blockUI block="averbacaoDataTable" trigger="averbacaoDataTable">  
                            CARREGANDO...<br />  
                            <p:graphicImage value="/media/img/ajax-loader.gif"/>  
                        </p:blockUI>
                    </fieldset>
                    <br/>
                    
                    <fieldset class="ui-fieldset">
                        <legend><h:outputLabel value="Registros"/></legend>

                        <p:dataTable id="registroDataTable" var="reg" 
                                     value="#{managerBuscarImovel.verImovel.registros}"
                                     paginator="true" rows="5"
                                     paginatorTemplate="{FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"  
                                     paginatorPosition="bottom"
                                     rowsPerPageTemplate="5,10,15"
                                     draggableColumns="true"
                                     emptyMessage="Nenhum registro encontrado"
                                     >  
                            <f:facet name="header">  
                                Registros do Imóvel
                            </f:facet>

                            <p:column style="width:16px">  
                                <p:rowToggler />  
                            </p:column>
                            <p:column style="width:90px;">  
                                <f:facet name="header" >   
                                    Número   
                                </f:facet>  
                                <h:outputText value="#{reg.numero}" />  
                            </p:column>
                            <p:column>  
                                <f:facet name="header" >   
                                    Descricao 
                                </f:facet>  
                                <h:outputLabel value="#{reg.descricao.length() > 200 ? reg.descricao.substring(1, 200) : reg.descricao}" escape="false"/>  
                            </p:column>
                            <p:rowExpansion >  

                                <h:outputLabel value="#{reg.descricao}" escape="false" style="text-align: justify; text-justify: auto"/> 

                            </p:rowExpansion> 
                            <p:column style="width:90px;" headerText="Data" sortBy="#{reg.dataRegistro}">  
                                <h:outputText value="#{reg.dataRegistro}">
                                    <f:convertDateTime pattern="dd/MM/yyyy"/>
                                </h:outputText>
                            </p:column>    
                        </p:dataTable>
                        <p:blockUI block="registroDataTable" trigger="registroDataTable">  
                            CARREGANDO...<br />  
                            <p:graphicImage value="/media/img/ajax-loader.gif"/>  
                        </p:blockUI>
                    </fieldset>
                    <br/>
<!--                    <fieldset class="ui-fieldset" id="fieldAnexo" >
                        <legend><h:outputLabel value="Anexos"/></legend>-->
                        <!--                        <p:fileUpload fileUploadListener="{managerArquivo.handleFileUpload}"  
                                                              mode="advanced"  
                                                              update="msg"   
                                                              multiple="true" 
                                                              uploadLabel="Anexar"
                                                              label="Carregar"
                                                              cancelLabel="Cancelar"
                                                              allowTypes="/(\.|\/)(gif|jpe?g|png|pdf|tif|doc|docx|ppt|pptx|xls|xlsx)$/"
                                                              invalidFileMessage="Arquivo não suportado, favor verifique o tipo do arquivo."
                                                              invalidSizeMessage="Tamanho do arquivo é inválido."
                                                              sizeLimit="10000000"
                                                              />  -->


<!--                    </fieldset>-->


                    <fieldset class="ui-fieldset">
                        <legend><h:outputLabel value="Anexos: "/></legend>                        
                        <div style="width:100%;">
                            <p:lightBox id="imgAnexo"   >  
                                     <ui:repeat value="#{managerBuscarImovel.verImovel.anexo}" var="item">
                                         <h:outputLink value="imageUploadServlet/?anexo=#{item.id}" styleClass="outAnexo" title="#{item.nome}">
                                             <table>
                                                 <tr style="margin-bottom: 5px">
                                                     <td>
                                                        <p:graphicImage url="imageUploadServlet/?anexo=#{item.id}" style="width:80px; height:80px; 
                                                                    margin-right: 10px; " />
                                                     </td>    
                                                     <td>
                                                        <h:outputLabel value="#{item.nome}" />
                                                     </td>
                                                 </tr>
                                             </table>
                                                    
                                             </h:outputLink> 
                                      </ui:repeat>
                                </p:lightBox>  
                        </div>
                    </fieldset>

                    <div class="buttonAction">

                        <p:commandButton id="upa" icon="ui-icon-arrowreturnthick-1-w" value="Voltar"
                                         actionListener="#{managerImovel.redirect('indexImovel.xhtml')}" 
                                         update="@form" process="@form"/>

                        <p:ajaxStatus style="width:16px;height:16px;" id="ajaxStatusPanel">  
                            <f:facet name="start">  
                                <h:graphicImage value="/media/img/loading.gif" />  
                            </f:facet>  

                            <f:facet name="complete">  
                                <h:outputText value="" />  
                            </f:facet>  
                        </p:ajaxStatus>

                    </div>
                </p:panel>  
                <p:dialog widgetVar="verMap2" header="Imóvel Geocodificado" style="width:100%" modal="true">
                    <p:gmap center="-2.92867970, -41.75083009999999" zoom="13" type="HYBRID"
                            style="width:600px;height:400px"  
                            model="#{managerGmap.simpleModel}">
                        <p:ajax event="markerDrag" listener="#{managerGmap.onMarkerDrag}" update="msg"/>
                        <p:ajax event="overlaySelect" listener="#{managerGmap.onMarkerSelect}" />

                        <p:gmapInfoWindow>  
                            <h:outputLabel value="Registro: " /> 
                        </p:gmapInfoWindow>  
                    </p:gmap>  
                </p:dialog>
                <p:dialog widgetVar="verMap" header="Imóvel Geocodificado"
                          style="width:100%; height: 200px" modal="true">
                    <h:panelGrid columns="2">
                        <p:gmap 
                            center="#{managerBuscarImovel.centerMap}" zoom="33" type="HYBRID"
                            style="width:600px;height:400px"  
                            model="#{managerBuscarImovel.polygonModel}">

                            <p:ajax event="overlaySelect" 
                                    listener="#{managerBuscarImovel.onMarkerSelect}"/>

                            <p:gmapInfoWindow>  
                                <p:outputPanel style="text-align:center;display:block;margin:auto:">  
                                    <h:outputLabel value="Registro: " /> 
                                    <h:outputText value="#{managerBuscarImovel.markerPol.data}" />
                                </p:outputPanel>
                            </p:gmapInfoWindow>  
                        </p:gmap> 
                        <p:row>
                            <p:panel id="infoObj" header="Detalhes "  style="height: 200px; ">
                                <h:panelGrid columns="2"  styleClass="textAlignRightBold" style=" width: 60px;">
                                    <h:outputLabel value="Logradouro: " />
                                    <h:outputText value="#{managerBuscarImovel.imovelMap.tipo_logradouro.nome} #{managerBuscarImovel.imovelMap.logradouro}" />
                                    <h:outputLabel value="Número: " />
                                    <h:outputText value="#{managerBuscarImovel.imovelMap.numero}" />
                                    <h:outputLabel value="Bairro: " />
                                    <h:outputText value="#{managerBuscarImovel.imovelMap.bairro}" />
                                    <h:outputLabel value="Cidade: " />
                                    <h:outputText value="#{managerBuscarImovel.imovelMap.cidade.nom_cidade}" />
                                    <h:outputLabel value="Estado: " />
                                    <h:outputText value="#{managerBuscarImovel.imovelMap.cidade.cod_estado.nom_estado}" />
                                </h:panelGrid>verImovel
                            </p:panel>
                            <p:panel id="infoObjConf" header="Confrontações "  
                                     style="height: 200px; overflow: auto;">
                                <h:panelGrid columns="1"  styleClass="textAlignRightBold" style="width: 60px;">
                                    <h:outputLabel value="Frente: " />
                                    <h:outputText value="#{managerBuscarImovel.imovelMap.frente}" />
                                    <h:outputLabel value="Lado Direito: " />
                                    <h:outputText value="#{managerBuscarImovel.imovelMap.ladoDireito}" />
                                    <h:outputLabel value="Lado Esquerdo: " />
                                    <h:outputText value="#{managerBuscarImovel.imovelMap.ladoEsquerdo}" />
                                    <h:outputLabel value="Fundo: " />
                                    <h:outputText value="#{managerBuscarImovel.imovelMap.fundo}" />
                                </h:panelGrid>
                            </p:panel>
                        </p:row>
                    </h:panelGrid>
                </p:dialog>


            </h:form>
            <script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script>
        </ui:define>
    </ui:composition>
</html>

